{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "25.0"
     ]
    }
   ],
   "source": [
    "# variables should be lowercase in julia (and really everywhere...)\n",
    "# if you're not sure what to do, pretend you're in Python\n",
    "x = 10\n",
    "x +=  5      # x = 15\n",
    "x /= 3      # x = 5\n",
    "print(x^2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "not true = false\n",
      "true and false = false\n",
      "true or false = true\n",
      "true xor true = false\n",
      "true == false : false\n"
     ]
    }
   ],
   "source": [
    "# logical operators!\n",
    "println(\"not true = \", !true)\n",
    "println(\"true and false = \", true & false)   # and \n",
    "println(\"true or false = \", true | false)   # or\n",
    "println(\"true xor true = \", true $ true)    # xor\n",
    "println(\"true == false : \", true == false)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.0\n",
      "5.0\n",
      "2.718281828459045\n",
      "\n",
      "3.0\n",
      "3.0\n",
      "\n",
      "0.49999999999999994\n",
      "0.49999999999999994\n"
     ]
    }
   ],
   "source": [
    "# more math!\n",
    "println(sqrt(25))  # square root\n",
    "println(cbrt(125)) # cube root\n",
    "println(exp(1))    # e ^ x\n",
    "println()\n",
    "\n",
    "println(log(2, 8)) # log base 2 of 8\n",
    "println(log2(8))   # log base 2 of 8\n",
    "println()\n",
    "\n",
    "println(sin(pi/6)) # sine of pi/6 = 1/2\n",
    "println(sind(30))  # sine of 30 degrees\n",
    "\n",
    "# there are a ton of other functions, such as a gamma function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex\n"
     ]
    }
   ],
   "source": [
    "# Strings!\n",
    "# note that you have to use double quotes for strings\n",
    "# and single quotes for characters\n",
    "x = \"Hi my name is Alex\"\n",
    "println(x[end-3], x[end-2], x[end-1], x[end])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# functions!\n",
    "# below are the two ways to define functions\n",
    "function add(x,y) \n",
    "    x + y\n",
    "end\n",
    "\n",
    "add(x,y) = x + y\n",
    "add(2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5,6)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# functions can return multiple values\n",
    "function f(x, y)\n",
    "    x+y, x*y\n",
    "end\n",
    "\n",
    "f(2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x is less than y\n"
     ]
    }
   ],
   "source": [
    "# if - else statements\n",
    "function evaluate(x, y)\n",
    "    if x < y\n",
    "        println(\"x is less than y\")\n",
    "    elseif x > y\n",
    "        println(\"x is greater than y\")\n",
    "    else\n",
    "        println(\"x is equal to y\")\n",
    "    end\n",
    "end\n",
    "\n",
    "evaluate(1, 9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x bigger\n"
     ]
    }
   ],
   "source": [
    "# Another quick way to handle if-else situations is the '?:' operator\n",
    "x = 1; y = 2;\n",
    "println(x < y ? \"x bigger\":\"y bigger\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12345\n",
      "12345"
     ]
    }
   ],
   "source": [
    "# Loops\n",
    "\n",
    "i = 1\n",
    "while i <= 5\n",
    "    print(i)\n",
    "    i += 1\n",
    "end\n",
    "\n",
    "println()\n",
    "\n",
    "for i = 1:5\n",
    "    print(i)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.3.11",
   "language": "julia",
   "name": "julia-0.3"
  },
  "language_info": {
   "name": "julia",
   "version": "0.3.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
